package com.oneonefive.educationsystem.controller;

import com.oneonefive.educationsystem.domain.Arrange;
import com.oneonefive.educationsystem.domain.Login;
import com.oneonefive.educationsystem.dto.Result;
import com.oneonefive.educationsystem.service.ArrangeService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/arrange")
public class ArrangeController {
    @Resource
    ArrangeService arrangeService;

    @PostMapping
    @PreAuthorize("hasAuthority('admin')")
    public Result arrangeSave(@RequestBody List<Arrange> arrangeList) {
        return arrangeService.listSave(arrangeList);
    }


    @PutMapping
    @PreAuthorize("hasAuthority('admin')")
    public Result arrangeUpdate(@RequestBody List<Arrange> arrangeList) {
        return arrangeService.listUpdate(arrangeList);
    }

    //data:List<Arrange>
    @GetMapping("/1")
    public Result arrangeList(String term) {
        return arrangeService.arrangeList(term);
    }

    @GetMapping("/clazz")
    @PreAuthorize("hasAuthority('student')")
    public Result clazzArrange(String term,Authentication authentication) {
        Login principal = (Login) authentication.getPrincipal();
        return arrangeService.clazzArrange(term,principal.getUser());

    }

    //data:List<Arrange>
    @GetMapping("/teaArrange/{trId}")
    @PreAuthorize("hasAuthority('admin')")
    public Result teaArrange(@PathVariable Integer trId) {
        return arrangeService.teaArrange(trId);
    }


    //data:List<Arrange>
    @GetMapping("/stuArrange/{srId}")
    @PreAuthorize("hasAuthority('admin')")
    public Result stuArrange(@PathVariable String srId) {
        return arrangeService.stuArrange(srId);
    }


}

